<?php
/*
本系统由苏酷伊基于SiteHub项目二次开发
作者博客： https://www.sukuy.com/
后续更新地址： https://www.sukuy.com/navigation
作者QQ：3288637559
QQ交流群：884250547
任何第三方非官网在发布本系统时，不得删除该注释、版权信息、作者信息及官网等内容
*/
error_reporting(0);
require_once __DIR__ . '/includes/common.php';
$url = isset($_GET['url']) ? $_GET['url'] : '';
if (empty($url)) {
    header('Location: ../');
    exit;
}
function is_valid_url($url) {
    if (filter_var($url, FILTER_VALIDATE_URL) === false) {
        return false;
    }
    $url_parts = parse_url($url);
    if (!isset($url_parts['scheme']) || !in_array(strtolower($url_parts['scheme']), ['http', 'https'])) {
        return false;
    }
    if (!isset($url_parts['host'])) {
        return false;
    }
    return true;
}
if (!is_valid_url($url)) {
    header('Location: ../');
    exit;
}
global $conf;
$site_title = isset($conf['title']) ? $conf['title'] : '安全跳转提示';
$logo = '/assets/images/logo.png';
$warning_text = '请注意保护个人隐私和财产安全';
$button_text = '立即跳转';
$page_title = '将要访问';
$auto_redirect = '1';
$countdown_seconds = '5';
$ad_image = '';
$ad_link = '';
$blog_url = '/';
$wwwroot = '';
?>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="referrer" content="always">
    <meta name="robots" content="noindex, nofollow">
    <title><?= htmlspecialchars($page_title) ?></title>
    <link href="/favicon.ico" rel="shortcut icon" type="image/x-icon">
    <link rel="stylesheet" href="/assets/css/safe_redirect.css">
</head>
<body>
    <div id="linkPage" class="link-page">
        <div class="content">
            <div class="logo-img">
                <img src="<?= htmlspecialchars($logo) ?>" alt="<?= htmlspecialchars($site_title) ?>">
            </div>
            <div class="loading-item loading-others">
                <div class="flex loading-tip tip2">
                    <img class="loading-img" src="/assets/images/warning.png" alt="警告">
                    <div class="loading-text"><?= htmlspecialchars($warning_text) ?></div>
                </div>
                <div class="loading-topic">
                    <span>您即将离开 <a href="<?= htmlspecialchars($blog_url) ?>" class="loading-color2"><?= htmlspecialchars($site_title) ?></a>，去往</span>
                    <a class="loading-color2"><?= htmlspecialchars($url) ?></a>
                </div>
                <div class="flex-end">
                    <a class="loading-btn" href="<?= htmlspecialchars($url) ?>" target="_self" rel="noopener nofollow" id="redirect-btn"><?= htmlspecialchars($button_text) ?><span id="countdown-text"></span></a>
                </div>
            </div>
        </div>
        <?php if ($ad_image): ?>
        <div class="content">
            <?php if ($ad_link): ?>
            <a href="<?= htmlspecialchars($ad_link) ?>" target="_blank" rel="noopener nofollow">
            <?php endif; ?>
                <img class="ad_imgs" src="<?= htmlspecialchars($ad_image) ?>" alt="广告">
            <?php if ($ad_link): ?>
            </a>
            <?php endif; ?>
        </div>
        <?php endif; ?>
    </div>
    
    <script>
    // 自动跳转倒计时功能
    <?php if ($auto_redirect == '1'): ?>
    let countdownSeconds = <?= $countdown_seconds ?>;
    const redirectBtn = document.getElementById('redirect-btn');
    const countdownText = document.getElementById('countdown-text');
    const targetUrl = '<?= htmlspecialchars($url) ?>';
    
    function updateCountdown() {
        if (countdownSeconds > 0) {
            countdownText.textContent = '(' + countdownSeconds + '秒)';
            countdownSeconds--;
            setTimeout(updateCountdown, 1000);
        } else {
            // 倒计时结束，自动跳转
            window.location.href = targetUrl;
        }
    }
    
    // 页面加载完成后开始倒计时
    document.addEventListener('DOMContentLoaded', function() {
        updateCountdown();
    });
    
    // 点击按钮立即跳转
    redirectBtn.addEventListener('click', function(e) {
        e.preventDefault();
        window.location.href = targetUrl;
    });
    <?php endif; ?>
    </script>
</body>
</html>